package com.ymatou.iapi.couponservice.testcase;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.couponservice.parameter.UserReceiveCouponBean;
import com.ymatou.iapi.couponservice.parameter.UserReceiveResultInfo;
import com.ymatou.iapi.couponservice.service.UserReceiveCouponCall;
import com.ymatou.iapi.m.couponservice.parameter.CreateCouponBean;
import com.ymatou.iapi.m.couponservice.parameter.SellerCreateBatchBean;
import com.ymatou.iapi.m.couponservice.service.CreateCouponCall;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;

import com.ymttest.business.service.CouponCallService;
import com.ymttest.business.service.CouponManageCallService;
import com.ymttest.business.service.CouponServiceMCallService;

import com.ymttest.database.model.YmtCoupon;
import com.ymttest.database.model.YmtCouponBatch;
import com.ymttest.database.model.YmtCouponPrivateUserBound;
import com.ymttest.database.model.YmtCouponScenario;
import com.ymttest.database.model.YmtCouponSetting;
import com.ymttest.database.model.YmtCouponValue;

import com.ymttest.database.sqlwapper.YmtCouponBatchWapper;
import com.ymttest.database.sqlwapper.YmtCouponPrivateUserBoundWapper;
import com.ymttest.database.sqlwapper.YmtCouponScenarioWapper;
import com.ymttest.database.sqlwapper.YmtCouponSettingWapper;
import com.ymttest.database.sqlwapper.YmtCouponValueWapper;
import com.ymttest.database.sqlwapper.YmtCouponWapper;
import com.ymttest.utils.YMTDateUtil;

@TestSuite
public class Ts_UserReceiveCoupon {
	private static UserReceiveCouponBean userreceivecouponBean;
	private static UserReceiveCouponCall userreceivecouponCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("用户领取优惠券用例");
	}

	@Before
	public void caseUp() {
		userreceivecouponBean = new UserReceiveCouponBean();
		userreceivecouponCall = new UserReceiveCouponCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(userreceivecouponCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_001() {
		Logger.start(true, "用户领取优惠券-平台链接");
		try {

			CouponServiceMCallService couponCallService = new CouponServiceMCallService();

			// 平台优惠券-链接
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();	
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);

			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setUserId(20324128);		

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			VerifyReturn(createcouponBean);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_002() {
		Logger.start(true, "用户领取优惠券-商家券");
		try {
			CouponServiceMCallService couponCallService = new CouponServiceMCallService();	

			// 商家优惠券
			SellerCreateBatchBean couponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
			String batchCode = couponCallService.SellerCreateBatch(couponBatchBean).getBatchCode();

			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(batchCode);

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

			UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

			// 验证返回
			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(), "验证返回UserId");
			Logger.verifyEquals(true, userReceiveResult.getIsReceiveSuccess(), "验证返回UserId");
			Logger.verifyEquals(0, userReceiveResult.getReceiveFailReason(), "验证返回UserId");

			YmtCouponBatch couponBatch = new YmtCouponBatchWapper()
					.selectBysBatchCode(userreceivecouponBean.getBatchCode()).get(0);
			YmtCouponValue couponValue = new YmtCouponValueWapper()
					.selectByiCouponSettingId(couponBatch.getiCouponSettingId()).get(0);
			YmtCouponSetting couponSetting = new YmtCouponSettingWapper()
					.selectByiCouponSettingId(couponBatch.getiCouponSettingId()).get(0);
			YmtCouponScenario couponScenario = new YmtCouponScenarioWapper()
					.selectByiCouponScenarioId(couponSetting.getiScenarioId()).get(0);
			YmtCoupon coupon = new YmtCouponWapper().selectByiBatchId(couponBatch.getiBatchId()).get(0);
			YmtCouponPrivateUserBound couponPrivateUserBound = new YmtCouponPrivateUserBoundWapper()
					.selectBysCouponCode(coupon.getsCouponCode()).get(0);

			Logger.verifyEquals(couponPrivateUserBound.getsCouponCode(), userReceiveResult.getCouponCode(),
					"验证返回CouponCode");
			// 验证数据库
			Logger.verifyEquals(userreceivecouponBean.getUserId(), couponPrivateUserBound.getiUserId(),
					"验证数据库表Ymt_CouponPrivateUserBound中iUserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), couponBatch.getsBatchCode(),
					"验证数据库表Ymt_CouponBatch中BatchCode");
			Logger.verifyEquals(couponPrivateUserBound.getiBatchId(), couponBatch.getiBatchId(),
					"验证数据库表Ymt_CouponBatch与表Ymt_CouponPrivateUserBound中iBatchId");

			Logger.verifyEquals(1, couponSetting.getiReceiveCount(), "验证数据库表Ymt_CouponSetting中iReceiveCount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_003() {
		Logger.start(true, "用户领取优惠券-平台非链接");
		try {

			CouponServiceMCallService couponManageCallService = new CouponServiceMCallService();

			CreateCouponBean createcouponBean = couponManageCallService.setDefaultPlatformCreateCouponBeanForConversion();

			CreateCouponCall createCouponCall = couponManageCallService.createPlatformCoupon(createcouponBean);

			userreceivecouponBean = couponManageCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setUserId(20324128);

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

			UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

			// 验证返回
			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(),
					"验证返回BatchCode");
			Logger.verifyEquals(false, userReceiveResult.getIsReceiveSuccess(), "验证返回IsReceiveSuccess(");
			Logger.verifyEquals(19, userReceiveResult.getReceiveFailReason(), "验证返回ReceiveFailReason");
			Logger.verifyEquals("批次不能用于领取", userReceiveResult.getRemark(), "验证返回ReceiveFailReason");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_004() {
		Logger.start(true, "用户领取优惠券-不在领取时间范围");
		try {

			CouponServiceMCallService couponManageCallService = new CouponServiceMCallService();

			CreateCouponBean createcouponBean = couponManageCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			
			CreateCouponCall createCouponCall = couponManageCallService.createPlatformCoupon(createcouponBean);

			userreceivecouponBean = couponManageCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setUserId(20324128);
			
			Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();

	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -10); // 设置为前一天
	        dBefore = calendar1.getTime(); // 得到前一天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, -1); // 设置为后十天
	        dAfter = calendar2.getTime(); // 得到前一天的时间

	   
		new YmtCouponBatchWapper().setAcquireStartTime(createCouponCall.getBatchCode(), dBefore);
		new YmtCouponBatchWapper().setAcquireEndTime(createCouponCall.getBatchCode(), dAfter);
		
			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

			UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

			// 验证返回
			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(),
					"验证返回BatchCode");
			Logger.verifyEquals(false, userReceiveResult.getIsReceiveSuccess(), "验证返回IsReceiveSuccess(");
			Logger.verifyEquals(14, userReceiveResult.getReceiveFailReason(), "验证返回ReceiveFailReason");
			Logger.verifyEquals("超出领取结束时间", userReceiveResult.getRemark(), "验证返回ReceiveFailReason");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_005() {
		Logger.start(true, "用户领取优惠券-平台链接-批次不能用于领取");
		try {

			CouponServiceMCallService couponManageCallService = new CouponServiceMCallService();

			CreateCouponBean createcouponBean = couponManageCallService.setDefaultPlatformCreateCouponBeanForConversion();
			CreateCouponCall createCouponCall = couponManageCallService.createPlatformCoupon(createcouponBean);

			userreceivecouponBean = couponManageCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setUserId(20324128);

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

			UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

			// 验证返回
			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(),
					"验证返回BatchCode");
			Logger.verifyEquals(false, userReceiveResult.getIsReceiveSuccess(), "验证返回IsReceiveSuccess(");
			Logger.verifyEquals(19, userReceiveResult.getReceiveFailReason(), "验证返回ReceiveFailReason");
			Logger.verifyEquals("批次不能用于领取", userReceiveResult.getRemark(), "验证返回ReceiveFailReason");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_006() {
		Logger.start(true, "用户领取优惠券-平台链接-批次不存在");
		try {

			CouponServiceMCallService couponManageCallService = new CouponServiceMCallService();

			userreceivecouponBean = couponManageCallService.setUserReceiveCouponBean("99999999");
			userreceivecouponBean.setUserId(20324128);

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

			UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

			// 验证返回
			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(), "验证返回BatchCode");
			Logger.verifyEquals(false, userReceiveResult.getIsReceiveSuccess(), "验证返回IsReceiveSuccess(");
			Logger.verifyEquals(8, userReceiveResult.getReceiveFailReason(), "验证返回ReceiveFailReason");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_007() {
		Logger.start(true, "用户领取优惠券-平台链接-coupon相对立即生效的优惠券截止时间至23:59:59S-JIRACONN-13324");
		try {

			CouponServiceMCallService couponCallService = new CouponServiceMCallService();

			// 平台优惠券-链接
			CreateCouponBean createcouponBean = couponCallService.setDefaultPlatformCreateCouponBeanForRecieve();	
			
			createcouponBean.setEffectiveType(1);
			createcouponBean.setEffectiveValidType(0);
			createcouponBean.setEffectiveDays(1);
			
			CreateCouponCall createCouponCall = couponCallService.createPlatformCoupon(createcouponBean);
			Thread.sleep(1000);

			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());	

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			VerifyReturn(createcouponBean);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_008() {
		Logger.start(true, "用户领取优惠券-商家券- JIRACONN-15533 : 可以领取买手还未生效的优惠券 ");
		try {
			CouponServiceMCallService couponCallService = new CouponServiceMCallService();	

			// 商家优惠券
			SellerCreateBatchBean couponBatchBean = couponCallService.setDefaultSellerCreateBatchBean();
			
			Date dNow = new Date(); // 当前时间
			Date dBefore = new Date();

			Calendar calendar1 = Calendar.getInstance(); // 得到日历
			calendar1.setTime(dNow);// 把当前时间赋给日历
			calendar1.add(Calendar.DAY_OF_MONTH, 1); // 设置为前一天
			dBefore = calendar1.getTime(); // 得到前一天的时间

			couponBatchBean.setEffectiveStartDate(dBefore);
			String batchCode = couponCallService.SellerCreateBatch(couponBatchBean).getBatchCode();

			userreceivecouponBean = couponCallService.setUserReceiveCouponBean(batchCode);

			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

			UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

			// 验证返回
			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(), "验证返回UserId");
			Logger.verifyEquals(true, userReceiveResult.getIsReceiveSuccess(), "验证返回UserId");
			Logger.verifyEquals(0, userReceiveResult.getReceiveFailReason(), "验证返回UserId");

			YmtCouponBatch couponBatch = new YmtCouponBatchWapper()
					.selectBysBatchCode(userreceivecouponBean.getBatchCode()).get(0);
			YmtCouponValue couponValue = new YmtCouponValueWapper()
					.selectByiCouponSettingId(couponBatch.getiCouponSettingId()).get(0);
			YmtCouponSetting couponSetting = new YmtCouponSettingWapper()
					.selectByiCouponSettingId(couponBatch.getiCouponSettingId()).get(0);
			YmtCouponScenario couponScenario = new YmtCouponScenarioWapper()
					.selectByiCouponScenarioId(couponSetting.getiScenarioId()).get(0);
			YmtCoupon coupon = new YmtCouponWapper().selectByiBatchId(couponBatch.getiBatchId()).get(0);
			YmtCouponPrivateUserBound couponPrivateUserBound = new YmtCouponPrivateUserBoundWapper()
					.selectBysCouponCode(coupon.getsCouponCode()).get(0);

			Logger.verifyEquals(couponPrivateUserBound.getsCouponCode(), userReceiveResult.getCouponCode(),
					"验证返回CouponCode");
			// 验证数据库
			Logger.verifyEquals(userreceivecouponBean.getUserId(), couponPrivateUserBound.getiUserId(),
					"验证数据库表Ymt_CouponPrivateUserBound中iUserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), couponBatch.getsBatchCode(),
					"验证数据库表Ymt_CouponBatch中BatchCode");
			Logger.verifyEquals(couponPrivateUserBound.getiBatchId(), couponBatch.getiBatchId(),
					"验证数据库表Ymt_CouponBatch与表Ymt_CouponPrivateUserBound中iBatchId");

			Logger.verifyEquals(1, couponSetting.getiReceiveCount(), "验证数据库表Ymt_CouponSetting中iReceiveCount");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_UserReceiveCoupon_009() {
		Logger.start(true, "用户领取优惠券-不在领取时间范围");
		try {

			CouponServiceMCallService couponManageCallService = new CouponServiceMCallService();

			CreateCouponBean createcouponBean = couponManageCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			
			Date dNow = new Date(); // 当前时间
			Date dBefore = new Date();

			Calendar calendar1 = Calendar.getInstance(); // 得到日历
			calendar1.setTime(dNow);// 把当前时间赋给日历
			calendar1.add(Calendar.DAY_OF_MONTH, 1); // 设置为前一天
			dBefore = calendar1.getTime(); // 得到前一天的时间

			createcouponBean.setAcquireStartTime(dBefore);
			
			CreateCouponCall createCouponCall = couponManageCallService.createPlatformCoupon(createcouponBean);

			userreceivecouponBean = couponManageCallService.setUserReceiveCouponBean(createCouponCall.getBatchCode());
			userreceivecouponBean.setUserId(20324128);
			
			userreceivecouponCall.setData(userreceivecouponBean);
			userreceivecouponCall.callService();

			Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

			UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

			// 验证返回
			Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
			Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(),
					"验证返回BatchCode");
			Logger.verifyEquals(false, userReceiveResult.getIsReceiveSuccess(), "验证返回IsReceiveSuccess(");
			Logger.verifyEquals(13, userReceiveResult.getReceiveFailReason(), "验证返回ReceiveFailReason");
			Logger.verifyEquals("未到领取开始时间", userReceiveResult.getRemark(), "验证返回ReceiveFailReason");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	private void VerifyReturn(CreateCouponBean createcouponBean) throws InterruptedException {
		Logger.verifyEquals("0", userreceivecouponCall.getCode(), "验证返回code");
		Logger.verifyEquals("操作成功！", userreceivecouponCall.getMessage(), "验证返回Message");

		UserReceiveResultInfo userReceiveResult = userreceivecouponCall.getUserReceiveResult();

		// 验证返回
		Logger.verifyEquals(userreceivecouponBean.getUserId(), userReceiveResult.getUserId(), "验证返回UserId");
		Logger.verifyEquals(userreceivecouponBean.getBatchCode(), userReceiveResult.getBatchCode(), "验证返回BatchCode");
		Logger.verifyEquals(true, userReceiveResult.getIsReceiveSuccess(), "验证返回IsReceiveSuccess(");
		Logger.verifyEquals(0, userReceiveResult.getReceiveFailReason(), "验证返回ReceiveFailReason");

		YmtCouponBatch couponBatch = new YmtCouponBatchWapper().selectBysBatchCode(userreceivecouponBean.getBatchCode())
				.get(0);
		YmtCouponValue couponValue = new YmtCouponValueWapper()
				.selectByiCouponSettingId(couponBatch.getiCouponSettingId()).get(0);
		YmtCouponSetting couponSetting = new YmtCouponSettingWapper()
				.selectByiCouponSettingId(couponBatch.getiCouponSettingId()).get(0);
		YmtCouponScenario couponScenario = new YmtCouponScenarioWapper()
				.selectByiCouponScenarioId(couponSetting.getiScenarioId()).get(0);
		YmtCoupon coupon = new YmtCouponWapper().selectByiBatchId(couponBatch.getiBatchId()).get(0);
		YmtCouponPrivateUserBound couponPrivateUserBound = new YmtCouponPrivateUserBoundWapper()
				.selectBysCouponCode(coupon.getsCouponCode()).get(0);

		// 验证数据库
		Logger.verifyEquals(userreceivecouponBean.getUserId(), couponPrivateUserBound.getiUserId(),
				"验证数据库表Ymt_CouponPrivateUserBound中iUserId");
		Logger.verifyEquals(userreceivecouponBean.getBatchCode(), couponBatch.getsBatchCode(),
				"验证数据库表Ymt_CouponBatch中BatchCode");
		Logger.verifyEquals(couponPrivateUserBound.getiBatchId(), couponBatch.getiBatchId(),
				"验证数据库表Ymt_CouponBatch与表Ymt_CouponPrivateUserBound中iBatchId");
		Logger.verifyEquals(couponPrivateUserBound.getsCouponCode(), userReceiveResult.getCouponCode(),
				"验证返回CouponCode");

		// 平台券异步更新该字段，放到消息总线更新
		Thread.sleep(5000);
		Logger.verifyEquals(1, couponSetting.getiReceiveCount(), "验证数据库表Ymt_CouponSetting中iReceiveCount");

		List<YmtCouponPrivateUserBound> bounds = new YmtCouponPrivateUserBoundWapper()
				.selectByBatchIdAndUserId(couponBatch.getiBatchId(), userreceivecouponBean.getUserId());
		int remainReceiveTimes = couponSetting.getiMaxUseTimePerUser() - bounds.size();

		Logger.verifyEquals(remainReceiveTimes, userReceiveResult.getRemainReceiveTimes(), "验证返回RemainReceiveTimes");
		
		// coupon相对立即生效的优惠券截止时间至23:59:59S-JIRACONN-13324
		if(createcouponBean.getEffectiveType()==1&&createcouponBean.getEffectiveValidType()==0)
		{
			Date validStart = coupon.getdValidStart();
			Calendar calendar1 = Calendar.getInstance(); // 得到日历
			calendar1.setTime(validStart);// 把当前时间赋给日历
			calendar1.add(Calendar.DAY_OF_MONTH, createcouponBean.getEffectiveDays()); // 设置为前一天
			Date validEnd = calendar1.getTime(); // 得到前一天的时间
			
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
			
			Logger.verifyEquals(sdf.format(validEnd).substring(0, 10)+" 23:59:59.000", sdf.format(coupon.getdValidEnd()), "验证Coupon表ValidEnd");

		}
	}   
}
